﻿#region Using Directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace Nihongo
{
    public class Word : LanguageComponentBase
    {
        private readonly string _word;
        private readonly string _kana;
        private readonly string _romaji;

        public Word(string word, string kana)
        {
            _word = word;
            _kana = kana;
            _romaji = Nihongo.Romaji.Render(this);
        }

        public Word(string kana) : this(kana, kana)
        {
        }

        public override string Kana
        {
            get { return _kana; }
        }

        public override string Romaji
        {
            get { return _romaji; }
        }

        public override string ToString()
        {
            return _word;
        }

        public static Word Concat(Word first, string second)
        {
            return new Word(first + second, first.Kana + second);
        }

        /// <summary>
        /// Removes characters from the end of a word.
        /// </summary>
        /// <param name="charCount">Specifies the number of characters to remove.</param>
        /// <returns>The trimmed word.</returns>
        public Word TrimEnd(int charCount)
        {
            string trimmedWord = _word.Substring(0, _word.Length - charCount);
            string trimmedKana = _kana.Substring(0, _kana.Length - charCount);

            return new Word(trimmedWord, trimmedKana);
        }
    }
}
